/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package myheartsgame;

import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author KaKa
 */
public class Dealer {
    private Random random;
    private int countPlayer;
    public ArrayList<Card> _gameCards;

    public Dealer() {

        random = new Random();
        InitCards();
        RefeshAll();
    }

    public void InitCards() {

        _gameCards = new ArrayList<Card>();
        int iNumberCard;
        int iSuit;

        for(iNumberCard = 2; iNumberCard <= CardsInfo.A; iNumberCard++) {
            for(iSuit = 0; iSuit < 4; iSuit++){
                _gameCards.add(new Card(iSuit, iNumberCard));
            }
        }
    }

    // Trao bai
    public void RefeshAll() {

        int CardSelected;
        int CardChanged;
        countPlayer = 0;
        int timesChange = 100;
        for(int iChange = 0; iChange < timesChange; iChange++) {

            // 0 <= random.nextInt(52) < 52
            CardSelected = random.nextInt(52);
            CardChanged = random.nextInt(52);
                        
            /* _gameCards[CardSelected] = _gameCards[CardChanged]
             * temp = _gameCards[CardSelected] */
            Card temp = _gameCards.set(CardSelected, _gameCards.get(CardChanged));
            _gameCards.set(CardChanged, temp);
        }
    }

    public ArrayList<String> DealToPlayer() {
        ArrayList<String> playerCard = new ArrayList<String>();

        int indexPlayer = countPlayer * 13;
        if (countPlayer >= 4) {
            return null;
        }

        for (int iCount = 0; iCount < 13; iCount++) {
            String cardInfo = _gameCards.get(indexPlayer + iCount).GetCardInfo();
            playerCard.add(cardInfo);
        }

        countPlayer++;
        return playerCard;
    }
}
